<% Option Explicit %>

<%
Dim adoConn					'Database Connection Variable Object
Dim strFilename, sid, pid


strFilename = Request.QueryString("filename")
sid = Request.QueryString("sid")
pid = Request.QueryString("pid")

If strFilename <> "" Then
    DelFile strFilename
	DelRecord strFilename, sid, pid
End if

%>


<%
'*********************************************
'***	Delete Record
'*********************************************
Private Sub DelRecord(ByVal filename, ByVal sid, ByVal pid)
	
	Dim sepPos, ticks
	Dim strSQL
	
	sepPos = InStr(filename, "_")
	If sepPos > 0 Then
		ticks = Mid(filename, 1, sepPos-1)
		filename = Replace(Mid(filename, sepPos+1), "'", "''")
		Call connect()
			strSQL = "sp_RemoveFile '"& filename &"', "& ticks &", '"& sid &"', "& pid
			' Response.Write(strSQL)
			adoConn.Execute strSQL
		Call disconnect()
	End if
End Sub

'*********************************************
'***	Delete File
'*********************************************
' Procedure name	: DelFile
' Argument 			: sFile = Filename
' Action			: Physically remove a file
' Return			: Not return 
Private Sub DelFile(ByVal sFile)
	Dim oFS
	
	Set oFS = Server.CreateObject("Scripting.FileSystemObject")
	If Cint(pid)=0 Then
	    sFile = Server.MapPath("Temp/" & sid) & "\" & sFile
	Else
	    sFile = Server.MapPath("project_files/" & pid) & "\" & sFile
	End if
		
	' Response.Write(sFile)
	If oFS.FileExists(sFile) Then	    
		oFS.DeleteFile sFile, True
	End if
End Sub


'*********************************************
'***	Miscellaneous
'*********************************************
Private Sub connect()
	Dim connStr
	Dim strSQLServerName, strSQLDBUserName, strSQLDBPassword, strSQLDBName
	
	'Set SQL Server Configuration
	strSQLServerName 	= "(local)"
	strSQLDBUserName 	= "sa"
	strSQLDBPassword 	= "admin"
	strSQLDBName 		= "irl"
	
	'connStr = "Provider=SQLOLEDB;Connection Timeout=90;Server="& strSQLServerName &";User ID="& strSQLDBUserName &";Password="& strSQLDBPassword &";Database=" & strSQLDBName
	connStr = "Provider=SQLOLEDB;Connection Timeout=90;Server=(local);Database=irl;Integrated Security=SSPI"
	
	'Initalize and Open ADO Connection
	Set adoConn = Server.CreateObject("ADODB.Connection")	
	adoConn.Open connStr
	
End Sub

Public Sub disconnect()
		
	'Close Database Connection
	If IsObject(adoConn) Then
		adoConn.Close
		Set adoConn = Nothing
	End If
End Sub
%>